package com.haoshuang.zhouzhoubang.ui.page.shop.car

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.bean.ShopBean5
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ShopCarViewModel : BaseViewModel() {
    val getData2 = StatefulMutableLiveData<Any>()
        fun getData2(vararg params: Pair<String, Any?>) {
            rxLifeScope.launch {
                request<Any>("api/goods/remove_cart", *params,
                    onStart = {
                        getData2.value = StateData.Loading
                    },
                    onError = { code, msg ->
                        getData2.value = StateData.Error(code, msg)
                    }, onSuccess = {
                        getData2.value = StateData.Success(it)
                    })
            }
        }
    val getData6 = StatefulMutableLiveData<Any>()
        fun getData6(vararg params: Pair<String, Any?>) {
            rxLifeScope.launch {
                request<Any>("api/goods/change_cart_num", *params,
                    onStart = {
                        getData6.value = StateData.Loading
                    },
                    onError = { code, msg ->
                        getData6.value = StateData.Error(code, msg)
                    }, onSuccess = {
                        getData6.value = StateData.Success(it)
                    })
            }
        }
        val getData = StatefulMutableLiveData<ArrayList<ShopBean5>>()
            fun getData(vararg params: Pair<String, Any?>) {
                rxLifeScope.launch {
                    request<ArrayList<ShopBean5>>("api/goods/get_cart_list", *params,
                        onStart = {
                            getData.value = StateData.Loading
                        },
                        onError = { code, msg ->
                            getData.value = StateData.Error(code, msg)
                        }, onSuccess = {
                            getData.value = StateData.Success(it)
                        })
                }
            }
}